﻿Imports System.Data.SqlClient

Public Class AdmFindUsers
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    Protected Sub btnFind_Click(sender As Object, e As EventArgs) Handles btnFind.Click
        Dim strHtml As String = ""
        Dim strUID, strVID, supervisor As String
        Dim firstname, lastname, location As String
        Dim active As String
        Dim HTMLString As String = ""
        Dim sSQL As String = ""
        Dim objfind As New GetData
        Dim objrd As SqlDataReader = Nothing
        Dim ps As New PreparedStatement(sSQL)
        Dim act As String
        Dim strErr As String = ""
        If (Session("admin_ID") <> Nothing And Session("admin_ID") <> "") Then
            strUID = vid.Text
            strVID = sVID.Text
            firstname = txtFname.Text
            lastname = txtLname.Text
            location = txtLoc.Text
            sSQL = "select adminuser_id,GAPortal_ID,first_name,last_name,location,supervisor,active from adm_user where 1=1"
            If strUID <> "" Then
                sSQL = sSQL & " and Upper(adminuser_id) like @admin_id"
            End If
            If strVID <> "" Then
                sSQL = sSQL & " and Upper(GAPortal_ID) like @id"
            End If
            If lastname <> "" Then
                sSQL = sSQL & " and Upper(last_name) like @lastname"
            End If
            If firstname <> "" Then
                sSQL = sSQL & " and Upper(first_name) like @firstname"
            End If
            If location <> "" Then
                sSQL = sSQL & " and Upper(location) like @location"
            End If
            ps.addParameter("admin_id", UCase(strUID))
            ps.addParameter("firstname", UCase(firstname))
            ps.addParameter("lastname", UCase(lastname))
            ps.addParameter("id", UCase(strVID))
            ps.addParameter("location", UCase(location))
            ps.strSql = sSQL
            Dim conn As SqlConnection = objfind.getConn()

            objrd = objfind.dr(ps, strErr, conn, objrd)
            If objrd.HasRows Then
                strHtml += "<table class='minorbox' cellspacing='1' width='100%' border=""0""  style=""background-color:#3399FF"">"
                strHtml += "<tr	><td class='gridheader'  style=""background-color:#AACCFF"">User ID</td>"

                strHtml += "<td class='gridheader' style=""background-color:#AACCFF"">First Name</td>"

                strHtml += "<td class='gridheader' style=""background-color:#AACCFF"">Last Name</td>"

                strHtml += "<td class='gridheader' style=""background-color:#AACCFF"">Location</td>"

                strHtml += "<td class='gridheader' style=""background-color:#AACCFF"">Supervisor</td>"

                strHtml += "<td class='gridheader' style=""background-color:#AACCFF"">Active</td></tr>"

                While (objrd.Read())
                    strUID = objrd("adminuser_id").ToString
                    strVID = objrd("GAPortal_ID").ToString
                    firstname = objrd("first_name").ToString
                    lastname = objrd("last_name").ToString
                    location = objrd("location").ToString
                    supervisor = objrd("supervisor").ToString
                    active = objrd("active").ToString
                    If active = 1 Then
                        act = "true"
                    Else
                        act = "false"
                    End If
                    HTMLString = HTMLString & vbCr & vbTab & vbTab & "<tr>"
                    HTMLString = HTMLString & "<td valign=""top""  style=""background-color:#FFF""><a href=""admedituser.aspx?aid=" & strVID & """>" & strUID & "&nbsp;</a></td>"
                    HTMLString = HTMLString & "<td valign=""top"" style=""background-color:#FFF"">" & firstname & "&nbsp;</td>"
                    HTMLString = HTMLString & "<td valign=""top"" style=""background-color:#FFF"">" & lastname & "&nbsp;</td>"
                    HTMLString = HTMLString & "<td valign=""top"" style=""background-color:#FFF"">" & location & "&nbsp;</td>"
                    HTMLString = HTMLString & "<td valign=""top"" style=""background-color:#FFF"">" & supervisor & "&nbsp;</td>"
                    HTMLString = HTMLString & "<td valign=""top"" style=""background-color:#FFF"">" & act & "&nbsp;</td></tr>"
                End While

                HTMLString = HTMLString & "</table>"
                strHtml += HTMLString


            Else
                strHtml = "No user was found"

            End If
            objfind.closeConn(conn)

            searchResult.InnerHtml = strHtml
        Else
            Response.Redirect("../adm_login.aspx")
        End If
    End Sub
End Class